package com.hmys.api.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hmys.api.mapper.WebCounselorMapper;
import com.hmys.api.model.WebCounselor;
import com.hmys.api.model.WebCounselorItem;
import com.hmys.api.model.WebCounselorWithBLOBs;
import com.hmys.api.service.WebCounselorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by chen365 on 2018/03/26.
 */
@Service
public class WebCounselorServiceImpl implements WebCounselorService {
    @Autowired
    private WebCounselorMapper webCounselorMapper;


    @Override
    public WebCounselorWithBLOBs selectByPrimaryKey(Long id) {
        webCounselorMapper.updatePageViewByPrimaryKey(id);
        return webCounselorMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<WebCounselorItem> selectItemByBean(Integer pageIndex, Integer pageSize, WebCounselor record) {
        if (StringUtils.isEmpty(pageIndex) || pageIndex < 1) {
            pageIndex = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 1) {
            pageSize = 10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        List<WebCounselorItem> list = webCounselorMapper.selectItemByBean(record);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<WebCounselorWithBLOBs> selectByBean(Integer pageIndex, Integer pageSize, WebCounselor record) {
        if (StringUtils.isEmpty(pageIndex) || pageIndex < 1) {
            pageIndex = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 1) {
            pageSize = 10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        List<WebCounselorWithBLOBs> list = webCounselorMapper.selectByBean(record);
        return new PageInfo<>(list);
    }
}
